package cn.fzm.dao.impl;

import cn.fzm.dao.UserDao;
import cn.fzm.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @author Dremeue
 * @create 2019-09-27 17:31
 **/
public class UserDaoImpl implements UserDao {

    private SqlSessionFactory sqlSessionFactory;

    public UserDaoImpl() {
    }

    public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public User queryUserById(int id) {
        SqlSession sqlSession = this.sqlSessionFactory.openSession();
        User user = sqlSession.selectOne("queryUserById", id);
        return user;
    }

    @Override
    public List<User> queryUserByUsername(String username) {
        SqlSession sqlSession = this.sqlSessionFactory.openSession();
        List<User> list = sqlSession.selectList("queryUserByUsername", username);
        return list;
    }
}
